package legoclient;

import ServerClient.ClientServerCmd;
import ServerClient.TcpConnection;
import java.io.*;

/**
 *
 * @author Daniel
 */
public class ClientBackend {
    private static TcpConnection client;
    //private static String serverIp = "192.168.1.2";
    public static int tcpPort = 9070;
    public static String rtpPort = "9079";
    private AVReceive2 video;
    
    private ClientGUI gui;
    
    public ClientBackend(ClientGUI gui) {
        this.gui = gui;
        this.gui.update("Client Backend Started");
        //serverIp = gui.ipField.getText();        
    }
    
    //public getOutStream
        
    public boolean isConnected() {
        if(client != null)
            return client.isConnected();
        return false;
    }
    
    public void writeCmd(ClientServerCmd c) {
        if(isConnected()) {
            gui.update("Sending command:");
            client.writeCmd(c);
        } else {
            gui.update("Error can't send command, not Connected");
        }
                
    }
    
    public void connectToServer(String ip, int port) {
        gui.update("Connecting to Server: http://" + ip + ":" + port);
        client = new TcpConnection(ip, port);
    }
}
